package com.example.demo.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.demo.model.Employee;
import com.example.demo.service.EmployeeService;

@Controller
@RequestMapping("emp")
public class EmployeeController {

	@Resource
	private EmployeeService employeeService;
	
	@GetMapping("all")
	public  Object findAll(Map<String, Object> map) {
		map.put("emps", employeeService.findAll());
		return "employee/all";
	}
	
	@GetMapping("update_view")
	public String updateView(@RequestParam("eid") Integer eid,Map<String, Object> map) {
		map.put("emp", employeeService.finById(eid));
		return "employee/update";
	}
	
	@PostMapping("update")
	public String update(Employee emp,Map<String, Object> map) {
		boolean r=employeeService.update(emp);
		return "redirect:all";
	}
}
